import * as dayjs from "dayjs";

/**
 * 获取一个日期的星期几
 * @param time - 时间戳
 */
export function getWeekByDate(time: number) {
  // 映射对象
  const weekMap: { [key: number | string]: string } = {
    0: "周日",
    1: "周一",
    2: "周二",
    3: "周三",
    4: "周四",
    5: "周五",
    6: "周六",
  };

  return weekMap[dayjs(time).format("d")];
}

/**
 * 判断传递的时间是否今天
 * @param time - 时间戳
 */
export function isToday(time: number) {
  const now = dayjs();
  return now.format("YYYY-MM-DD") === dayjs(time).format("YYYY-MM-DD");
}

export function isTomorrow(time: number) {
  const now = dayjs().add(1, "day");
  return now.format("YYYY-MM-DD") === dayjs(time).format("YYYY-MM-DD");
}

export function isAfterTomorrow(time: number) {
  const now = dayjs().add(2, "day");
  return now.format("YYYY-MM-DD") === dayjs(time).format("YYYY-MM-DD");
}

/**
 * 获取一个日期的星期几, 匹配成 今天、明天、后天
 * @param time
 */
export function getWeekTwoByDate(time: number) {
  if (isToday(time)) {
    return "今天";
  } else if (isTomorrow(time)) {
    return "明天";
  } else if (isAfterTomorrow(time)) {
    return "后天";
  } else {
    return getWeekByDate(time);
  }
}
